package com.xxzb.pack0820;

import java.io.File;
import java.io.FileReader;
import java.io.Reader;

//字符流的读取
public class DemoB {
    public static void a() throws Exception {
        //读取源文件
        File file = new File("F:\\yongpangaofeng\\a.txt");
        //建立字符流读取通道
        Reader reader = new FileReader(file);
        //定义一个容器
        char[] chars = new char[10];
        //读取一次
        int len = reader.read(chars);
        System.out.println(chars);
        System.out.println(len);
        //关闭
        reader.close();
    }

    public static void b() throws Exception{
        //读取的源文件
        File file=new File("f:\\yongpangaofeng\\a.txt");
        //建立字符流读取通道
        Reader reader=new FileReader(file);
        char[] chars=new char[10];
        int len;
        while ((len=reader.read(chars))!=-1){
            String str=new String(chars,0,len);
            System.out.println(str);
        }
        reader.close();
    }

    public static void main(String[] args) throws Exception {
        a();
//        b();
    }
}
